﻿using Moven.ViewModels;
#if __IOS__
using System.ComponentModel;
using Xamarin.Forms;
#endif


namespace Moven.Views
{
	public partial class BookmarkCell
	{
#if __IOS__
		static readonly ImageSource CheckedImage = "checked.png", UncheckedImage = "unchecked.png";
#endif

		ArticleWithBookmark _article;
		public BookmarkCell()
		{
			InitializeComponent();
#if __IOS__
			var separator = new BoxView
			{
				Color = Statics.SeparatorColor,
				HeightRequest = 0.5,
				Margin = new Thickness(0, 0, 0, -4)
			};

			container.Children.Add(separator);

			checkBox.CheckedImage = CheckedImage;
			checkBox.UncheckedImage = UncheckedImage;
			checkBox.Size = 40;
			checkBox.EasingFunctionName = "CubicIn";
#endif

#if __ANDROID__
			checkBox.WidthRequest = checkBox.HeightRequest = 40;
#endif
		}

		protected override void OnBindingContextChanged()
		{
			var article = Article;

			if (article == null)
			{
				if (_article != null)
				{
					_article.ViewCell = null;
				}
				_article = null;
			}
			else
			{
				_article = article;
				article.ViewCell = this;
				checkBox.ToggleCommand = article.ToggleCommand;
				LongPressCommand = article.ToggleCommand;
				titleLabel.Text = article.Title;
			}
			base.OnBindingContextChanged();
		}
	}
}
